package com.pvdnc.nsocket.serialize;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public class GsonUtils {
    private static final Gson GSON=get();

    private static Gson get(){
        GsonBuilder builder=new GsonBuilder();
        builder.disableHtmlEscaping();
        return builder.create();
    }

    public static <T> String toJson(T obj){
        return GSON.toJson(obj);
    }

    public static <T> T fromJson(String json,Class<T> cls){
        try {
            return GSON.fromJson(json, cls);
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }
}
